package com.vlyman.exception;

import com.vlyman.rtn.RtnResult;
import com.vlyman.rtn.SystemRtn;
import com.vlyman.rtn.consts.IBaseRtn;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类描述：
 *  统一处理异常类
 * @author chenjs
 * @date 2018/12/30 10:26
 **/
@RestControllerAdvice
public class ControllerExceptionHandler {

    /**
     * 方法描述：
     *   根据错误异常信息匹配系统错误码返回给前台
     *  @author chenjs
     *  @param e 错误异常
     *  @return RtnResult
     *  @date 2018/12/30 10:58
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RtnResult handler(Exception e) {
        String exceptionCode = e.getMessage();
        IBaseRtn rtn = SystemRtn.getRtnByCode(exceptionCode);
        return RtnResult.setRtn(rtn);
    }
}
